package com.vrland.web.front;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import com.vrland.web.front.config.VrProperties;

public class WebAppInitializer extends
		AbstractAnnotationConfigDispatcherServletInitializer {

	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[] { RootConfig.class, SecurityConfig.class };
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class<?>[] { WebConfig.class };
	}

	@Override
	protected String[] getServletMappings() {
		return new String[] { "/" };
	}

	@Override
	public void onStartup(ServletContext servletContext)
			throws ServletException {
		super.onStartup(servletContext);
		setupEnv(servletContext);
	}

	private void setupEnv(ServletContext servletContext) {
		// see http://www.mkyong.com/spring/spring-profiles-example/
		servletContext.setInitParameter(VrProperties.SPRING_PROFILE,
				VrProperties.getProperty(VrProperties.SPRING_PROFILE));
	}

}
